<?php

namespace Core;

/**
 * 输出控制
 *
 * @author lxc
 */
class Response
{

	public $body_string = '';
	public $heade_arr = [];
	public $cookie_arr = [];

	public function __construct()
	{
		$this->heade_arr['httpStatus'] = 'HTTP/1.1 200 OK';
		$this->heade_arr['serverName'] = 'Server: FK-Blog-1.0';
		$this->heade_arr['contentType'] = 'Content-Type: text/html;charset=utf-8';
		$this->heade_arr['connettion'] = 'Connection: keep-alive';
		$this->heade_arr['contentLength'] = 'Content-Length: 2';
		$this->body_string = 'OK';
	}

	public function buildHead()
	{
		return implode("\r\n", $this->heade_arr);
	}

	/**
	 * 最终输出
	 */
	public function output($string = '')
	{
		$this->body_string = $string;
		$this->heade_arr['contentLength'] = 'Content-Length: ' . ( strlen($this->body_string) );
		return $output = $this->buildHead() . "\r\n\r\n" . $this->body_string;
	}

	public function setHttpStatus($code = 200, $description = 'OK')
	{
		$this->heade_arr['httpStatus'] = 'HTTP/1.1 ' . $code . ' ' . $description;
		return $this;
	}

	public function setServerName($name = 'FK-Blog-1.0')
	{
		$this->heade_arr['serverName'] = 'Server: ' . $name;
		return $this;
	}

	public function setCookie($name, $value = "", $expire = 0, $path = "", $domain = "", $secure = false, $httponly = false)
	{
		$this->heade_arr['cookie'][] = '';
		return $this;
	}

	public function setContentType($type = 'text/html;charset=utf-8')
	{
		$this->heade_arr['contentType'] = 'Content-Type: ' . $type;
		return $this;
	}

}
